Skip to content

fix: security hardening — path traversal, trust proxy, image allowlist#394

Merged
alari76 merged 1 commit intomainfrom
fix/security-hardening-apr12
Apr 12, 2026
Merged

fix: security hardening — path traversal, trust proxy, image allowlist#394
alari76 merged 1 commit intomainfrom
fix/security-hardening-apr12

Conversation

@alari76
Copy link
Copy Markdown
Contributor

@alari76 alari76 commented Apr 12, 2026

Summary

  • Path traversal in /api/opencode/models: Added realpathSync + allowed-roots validation to workingDir, matching the existing guard in /api/sessions/create. Prevents reading arbitrary filesystem paths via the models endpoint.
  • Trust proxy for rate limiters: Added app.set('trust proxy', true) early in Express setup (gated on TRUST_PROXY config). This ensures req.ip returns the real client IP behind nginx, so all rate limiters (API global, auth endpoint) work correctly.
  • Markdown image src allowlist: The img renderer in ChatView now only allows https: and data:image/ URIs. Other protocols (http, ftp, etc.) are blocked with a placeholder, preventing tracking beacons or protocol abuse from model-generated markdown.

Test plan

  • npm run lint — 0 errors
  • npm test — 1600/1600 tests pass
  • Verify /api/opencode/models?workingDir=/etc returns 403
  • Verify rate limiting still works with TRUST_PROXY=true behind nginx
  • Verify markdown images with https:// src render normally
  • Verify markdown images with http:// src show blocked placeholder

🤖 Generated with Claude Code

1. /api/opencode/models: validate workingDir with realpath + allowed-roots
   check, matching the existing guard in /api/sessions/create.

2. Express trust proxy: set app.set('trust proxy', true) when TRUST_PROXY
   is enabled so req.ip returns the real client IP for all rate limiters.

3. Markdown img renderer: restrict src to https: and data:image/ protocols
   to prevent tracking beacons and arbitrary protocol access from model output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alari76 alari76 force-pushed the fix/security-hardening-apr12 branch from c28cf6d to 938d369 Compare April 12, 2026 19:03
@alari76 alari76 merged commit 3db107a into main Apr 12, 2026
2 checks passed
@alari76 alari76 deleted the fix/security-hardening-apr12 branch April 12, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant